package com.qch.kafka.demo.config;

import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.KafkaAdmin;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author qch
 * @Date 2021/5/29
 */
@Configuration
public class KafkaConfig {
    @Bean
    public NewTopic topic1(){
        return new NewTopic("nptc-01",3,(short)1);
    }
    @Bean
    public NewTopic topic2(){
        return new NewTopic("nptc-02",5,(short)1);
    }

    /**
     * 使用自定义的kafkaAdmin
     * 自带的kafkaAmin 能够检查并自动创建主题
     * @return
     */
    @Bean
    public KafkaAdmin kafkaAdmin(){
        Map<String,Object>configs=new HashMap<>();
        configs.put("bootstrap.servers","192.168.142.135:9092");
        KafkaAdmin kafkaAdmin = new KafkaAdmin(configs);
        return kafkaAdmin;
    }
}
